package Lab4;

import lombok.Data;

import java.awt.*;

/**
 * Title : Cat.java
 * Description: This class contains the definition of a cat.
 * Copyright : Copyright (c) 2006 - 2021
 *
 * @author Yibai Jiang
 * @version 1.5
 */
@Data
public class Cat {
    // 构造方法
    public Cat(String name, String furType, boolean tail, Color colour, int speed) {
        setName(name);
        setColour(colour);
        setFurType(furType);
        setTail(tail);
        setSpeed(speed);
    }

    // Declaration of instance variables.
    private String name;
    private String furType;
    private Boolean tail;
    private Color colour;
    private int speed;
    private int cot;

    public void printNameAndSpeed() {
        System.out.println("Name:" + this.name + "  Speed:" + this.speed);
    }

    public void printNameAndColor() {
        System.out.println("Name:" + this.name + "  Colour:" + this.colour);
    }

    /**
     * This is the sleep method for the cat. It dictates the number of
     * minutes the cat sleeps.
     *
     * @param duration The number of minutes to sleep.
     */
    public void sleep(int duration) {
        System.out.println("I am sleeping for " + duration + " minutes.");
    }

    /**
     * This method allows the cat to run. The distance (in a straight line)
     * the cat runs is dependent on how long the cat runs and whether or not
     * it is running in a zigzag.
     *
     * @param duration The number of minutes to run.
     * @param zigzag   Whether to run in a zigzag pattern.
     * @return int Number of metres ran.
     */
    public int run(int duration, boolean zigzag) {
        System.out.println("I am running "
                + (zigzag ? "in a zigzag" : "straight")
                + " for "
                + duration + " minutes.");
        int distanceRun = duration * speed; // assuming speed is metres per minute
        if (zigzag) {
/* When in zigzag, distance is 1/3 of what it would have been if
the cat was going straight. */
            return distanceRun / 3;
        } else return distanceRun;
    }

    /*
     * This is a toString --inClass-- method
     *
     * @param void
     * @return String of all attributes in Cat class
     * */
    public String toString() {
        return getName() + "+" + getFurType() + "+" + getColour() + "+" + getSpeed() + "+" + getTail();
    }
    // region 外部调用方法
   /* public ArrayList<String> attrToString() {
        ArrayList<String> attrList = new ArrayList<String>();
        Field[] attrs = this.getClass().getDeclaredFields();
        for (Field attr : attrs) {
            String attrStr = attr.getName();
            attrList.add(attrStr);
        }
        return attrList;
    }


     *
     *
    public Map<String, String> allToString() {
        Map<String, String> map = new HashMap<String, String>();
        ArrayList<String> arrayList = this.attrToString();
        for (String attr : arrayList) {
            try {
                map.put(attr, this.getClass().getField(attr).get(this).toString());
            } catch (Exception ignored) {

            }
        }
        return map;
    }*/
    // endregion
}
